﻿using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using EnetaMvc.Infrastructure;

namespace EnetaMvc.Validation
{
    public abstract class BaseValidator<T> : IValidator<T>
    {
        public virtual MultiValidationResult Validate(T instance)
        {
            var context = new ValidationContext(instance, null, null);
            var validationErrors = new List<ValidationResult>();

            Validator.TryValidateObject(instance, context, validationErrors, true);
            return new MultiValidationResult(validationErrors);
        }
    }
}
